[release/5.0-rc2] Fix default handling for value types when converter based on interface (#42319) #42406
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #42319 to release/5.0-rc2.
Customer Impact
InvalidOperationException
andAccessViolationException
(System.Text.Json Access Violation Exception (Attempted to read or write protected memory) #40878)JsonIgnoreCondition.WhenWritingDefault
is not honored when a property is a struct, the property is thedefault
value, a custom converter is provided, and the converter'sTypeToConvert
istypeof(object)
or an interface. The expected behavior is for the property to be ignored and to not call the converter.This is not a common usage pattern (polymorphic converter implementations). The workaround is to specialize the converter to handle to specific type of the property, or to not use the converter if unnecessary.
Example highlighting the issue:
Testing
Extensive tests have been added. Fix has been verified in reporting project. We don't expect a theme around issues polymorphic converter usages to develop, but will this will be an area to focus on in an oncoming fuzz testing and validation effort.
Risk
The fix is targeted to the scenario it fixes. It is unlikely to break other areas. There is no perf regression to the happy path.